// setAll功能的哈希表
// 测试链接 : https://www.nowcoder.com/practice/7c4559f138e74ceb9ba57d76fd169967
// 提交以下的code，可以直接通过

#include <bits/stdc++.h>

using namespace std;

unordered_map<int, pair<int, int>> m;
int setAllValue;
int setAllTime; // 记录调用 setAll 的时间
int cnt; // 时间戳

// 快读
int read()
{
    char ch = getchar();
    int x = 0, f = 1;
    while(ch < '0' || ch > '9')
    {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = 10 * x + ch - '0';
        ch = getchar();
    }
    return f * x;
}

void put(int key, int value)
{
    m[key] = {value, cnt++};
}

int get(int key)
{
    if(!m.count(key)) return -1;
    auto [value, time] = m[key];
    if(time > setAllTime) return value;
    else return setAllValue;
}

void setAll(int value)
{
    setAllTime = cnt++;
    setAllValue = value;
}

int main()
{
    int n = read();
    for(int i = 1; i <= n; ++i)
    {
        int opt = read();
        if(opt == 1)
        {
            int key = read(), value = read();
            put(key, value);
        }
        else if(opt == 2)
        {
            int key = read();
            printf("%d\n", get(key));
        }
        else
        {
            int value = read();
            setAll(value);
        }
    }

    return 0;
}